﻿using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Repositories;

namespace AbpProjectTemplate
{
    public abstract class AppService : Jy.Abp.Application.AppService
    {

        
    }

    public abstract class AppService<TEntity, TPrimaryKey> : AppService
        where TEntity : class, IEntity<TPrimaryKey>
    {
        protected readonly IRepository<TEntity, TPrimaryKey> Repository;

        public AppService(IRepository<TEntity, TPrimaryKey> repository)
        {
            Repository = repository;
        }

        /// <summary>
        /// id获取实体数据 如果不存在则抛出异常
        /// </summary>
        protected virtual Task<TEntity> GetEntityByIdAsync(TPrimaryKey id)
        {
            return Repository.GetAsync(id);
        }
    }

    public abstract class AppService<TEntity> : AppService<TEntity, int>
       where TEntity : class, IEntity<int>
    {
        public AppService(IRepository<TEntity, int> currentRepository) : base(currentRepository)
        {

        }
    }
}

